package com.woniu.adapter;

import com.woniu.outlet.dao.PotentialMessageMapper;
import com.woniu.outlet.po.CompanyWarn;
import com.woniu.outlet.po.PotentialMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Transactional
public class CompanyWarnAdapter {

    @Autowired
    private PotentialMessageMapper potentialMessageMapper;

    public void warn(List<CompanyWarn> companyWarns){
        for(CompanyWarn companyWarn:companyWarns){
            //然后到消息队列里面发消息
            PotentialMessage potentialMessage = new PotentialMessage();
            potentialMessage.setPotentialmessageExchange("potentialcustomer_exchange");
            potentialMessage.setPotentialmessageKey("potentialcustomer.xxx");
            potentialMessage.setPotentialmessageCount(10);
            potentialMessage.setPotentialmessageContext(""+companyWarn.getCompanyId()+","+"warn");
            potentialMessage.setPotentialmessageStatus(0);
            //将这个message存到数据库
            potentialMessageMapper.insert(potentialMessage);
        }

    }

}
